package com.demo.springbooot_demo.service;

import com.demo.springbooot_demo.pojo.LoginUser;
import com.demo.springbooot_demo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private IUserService userService ;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //从数据库中取出user
        User user = userService.findByUserName(username);
        //包装成返回类型返回
        return new LoginUser(user);
    }
}
